home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / updcrc.iqc / updcrc.inc
Text File  |  1985-08-04  |  3KB  |  60 lines

  1. {
  2. UPDCRC
  3. Author      : Scott Murphy (CIS address 70156,263)
  4.  
  5. Purpose     : used to compute the cyclic redundancy check (CRC)
  6.               for XMODEM protocol communications programs.
  7.  
  8. Environment : Turbo Pascal for 8086/88/186/286 based computers.
  9.  
  10. External
  11. Requirements: UPDCRC requires one integer variable inherited from the
  12.               block to which it belongs. The name of this variable
  13.               is assumed to be CRCVAL. If you wish to use a different
  14.               name, change the references to CRCVAL to the name of your
  15.               choice.
  16.  
  17. Usage       : A file sent or recieved in XMODEM-CRC format consists of blocks
  18.               of 133 bytes as follows: <SOH><BLK#><1-BLK#><128 bytes of data>
  19.               <hi byte of CRC><lo byte of CRC>.  A reciever tests for a
  20.               valid block by initializing CRCVAL to 0, then passes each
  21.               of the 128 data bytes, and the two CRC bytes through UPDCRC.
  22.               If CRCVAL = 0 at the end of this cycle, the data block is
  23.               valid and should be accepted.  A sender prepares a block
  24.               by setting CRCVAL to 0 and passing all 128 data bytes, and two
  25.               zero bytes through UPDCRC. The two bytes of the CRCVAL generated
  26.               replace the final two bytes of the block to be sent.
  27.  
  28. Example     :  Type block = array[1..133] of byte;
  29.                Function BlockCRC(Var sector : block) : integer;
  30.                (* Assumes a block as described in 'Usage' above has
  31.                   been stored verbatim in an array of type block *)
  32.                Var
  33.                  crcval, i : integer;
  34.  
  35.                  (*$I updcrc.inc*)
  36.  
  37.                begin
  38.                  crcval := 0;
  39.                  for i := 4 to 133 do
  40.                    updcrc(sector[i]);
  41.                  BlockCRC := crcval
  42.                end;
  43.  
  44. Acknowledment : This routine is a translation of equivalent code
  45.                 from the CP/M public domain utility XMODEM.ASM,
  46.                 Ver. 10.3.
  47. }
  48. procedure updcrc(a : byte);
  49. begin
  50.    inline( $8A/$46/$04/        {MOV     AL,[BP+04]}
  51.            $8B/$1E/crcval/     {MOV     BX,crcval}
  52.            $B9/$08/$00/        {MOV     CX,0008}
  53. {loop0}    $D0/$E0/            {SHL     AL,1}
  54.            $D1/$D3/            {RCL     BX,1}
  55.            $73/$04/            {JNC     loop1}
  56.            $81/$F3/$21/$10/    {XOR     BX,$1021}
  57. {loop1}    $E2/$F4/            {LOOP    loop0}
  58.            $89/$1E/crcval)     {MOV     crcval,BX}
  59. end;
  60.